<%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>55社区</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <%--引入公共样式--%>
    <jsp:include page="common.jsp"></jsp:include>
</head>
<body>
<header data-am-widget="header" class="am-header am-header-default sq-head ">
    <div class="am-header-left am-header-nav">
        <a href="javascript:history.back()" class="">
            <i class="am-icon-chevron-left"></i>
        </a>
    </div>
    <h1 class="am-header-title">
        <a href="" class="">购物车</a>
    </h1>
</header>
<div style="height: 49px;"></div>
<!--购物车空的状态-->
<div class="login-logo">
    <img src="${ctx}/static/images/logo.png">
    <p>亲、您的购物车还是空空的哦，快去装满它!</p>
    <a href="index.html" class="goshopping">前去逛逛</a>
</div>
<ul class="shopcart-list">

    <c:forEach var="bean" items="${shopCartMapList}" varStatus="ss">
        <li>
            <label class="am-checkbox am-warning">
                <input type="checkbox" checked="checked" value="${bean.shopcart_id}" data-am-ucheck checked>
            </label>
            <a href="detail.html"><img src="${ctx}/static/images/${bean.goods_img}" class="shop-pic"/></a>
            <div class="shop-list-mid">
                <div class="tit"><a href="goods/goodsDetail.do?goods_id=${bean.goods_id}">${bean.goods_name}</a></div>
                <div class="d-stock">
                    <a class="decrease">-</a>
                    <input goods_id="${bean.goods_id}" readonly="" class="text_box" name="" type="text"
                           value="${bean.shopcart_num}">
                    <a class="increase">+</a>
                </div>
            </div>
            <b class="shop-list-price">￥${bean.goods_price} </b>
            <div class="del"><i class="am-icon-trash" shopcart_id="${bean.shopcart_id}"></i></div>
        </li>

    </c:forEach>


    <%--   <li>
           <label class="am-checkbox am-warning">
               <input type="checkbox" checked="checked" value="" data-am-ucheck checked>
           </label>
           <a href="detail.html"><img src="images/test3.png" class="shop-pic"/></a>
           <div class="shop-list-mid">
               <div class="tit"><a href="detail.html">法国加力果12个装 进口新鲜水果 嘎啦苹果 包邮</a></div>
               <div class="d-stock">
                   <a class="decrease">-</a>
                   <input id="num" readonly="" class="text_box" name="" type="text" value="1">
                   <a class="increase">+</a>
               </div>
           </div>
           <b class="shop-list-price">￥169 </b>
           <div class="del"><i class="am-icon-trash"></i></div>
       </li>
       <li>
           <label class="am-checkbox am-warning">
               <input type="checkbox" checked="checked" value="" data-am-ucheck checked>
           </label>
           <a href="detail.html"><img src="images/test3.png" class="shop-pic"/></a>
           <div class="shop-list-mid">
               <div class="tit"><a href="detail.html">法国加力果12个装 进口新鲜水果 嘎啦苹果 包邮</a></div>
               <div class="d-stock">
                   <a class="decrease">-</a>
                   <input id="num" readonly="" class="text_box" name="" type="text" value="1">
                   <a class="increase">+</a>
               </div>
           </div>
           <b class="shop-list-price">￥169 </b>
           <div class="del"><i class="am-icon-trash"></i></div>
       </li>
       <li>
           <label class="am-checkbox am-warning">
               <input type="checkbox" checked="checked" value="" data-am-ucheck checked>
           </label>
           <a href="detail.html"><img src="images/test3.png" class="shop-pic"/></a>
           <div class="shop-list-mid">
               <div class="tit"><a href="detail.html">法国加力果12个装 进口新鲜水果 嘎啦苹果 包邮</a></div>
               <div class="d-stock">
                   <a class="decrease">-</a>
                   <input id="num" readonly="" class="text_box" name="" type="text" value="1">
                   <a class="increase">+</a>
               </div>
           </div>
           <b class="shop-list-price">￥169 </b>
           <div class="del"><i class="am-icon-trash"></i></div>
       </li>
       <li>
           <label class="am-checkbox am-warning">
               <input type="checkbox" checked="checked" value="" data-am-ucheck checked>
           </label>
           <a href="detail.html"><img src="images/test3.png" class="shop-pic"/></a>
           <div class="shop-list-mid">
               <div class="tit"><a href="detail.html">法国加力果12个装 进口新鲜水果 嘎啦苹果 包邮</a></div>
               <div class="d-stock">
                   <a class="decrease">-</a>
                   <input id="num" readonly="" class="text_box" name="" type="text" value="1">
                   <a class="increase">+</a>
               </div>
           </div>
           <b class="shop-list-price">￥169 </b>
           <div class="del"><i class="am-icon-trash"></i></div>
       </li>--%>
    <div style="height: 10px; background: #eee;"></div>
</ul>

<div class="shop-fix">

    <label class="am-checkbox am-warning">
        <input type="checkbox" checked="checked" value="" data-am-ucheck checked>
    </label>
    <a class="del">批量删除</a>
    <a href="tureorder.html" class="js-btn">去结算</a>
    <div class="js-text">
        <P>合计：<b>￥217.80</b></P>
        <p class="js-car">免费配送</p>
    </div>
</div>

<!--底部-->
<div style="height: 55px;"></div>
<div data-am-widget="navbar" class="am-navbar am-cf am-navbar-default sq-foot am-no-layout" id="">
    <ul class="am-navbar-nav am-cf am-avg-sm-4">
        <li>
            <a href="index.html" class="curr">
                <span class="am-icon-home"></span>
                <span class="am-navbar-label">首页</span>
            </a>
        </li>
        <li>
            <a href="category.html" class="">
                <span class="am-icon-th-large"></span>
                <span class="am-navbar-label">分类</span>
            </a>
        </li>

        <li>
            <a href="shopcart.html" class="">
                <span class="am-icon-shopping-cart"></span>
                <span class="am-navbar-label">购物车</span>
            </a>
        </li>
        <li>
            <a href="member.html" class="">
                <span class="am-icon-user"></span>
                <span class="am-navbar-label">我的55</span>
            </a>
        </li>
    </ul>
</div>


<script>

    //js加入购物车方法
    function addShopCart(myData) {
        $.post("${ctx}/shopCart/addShopCart.do", myData, function (data) {
            if (data.state == 0) {
                console.info(data.msg);
            } else {
                alert(data.msg);
            }
        });
    }

    //购物数量加减
    $(function () {
        $('.increase').click(function () {
            var self = $(this);
            var current_num = parseInt(self.siblings('input').val());
            current_num += 1;
            self.siblings('input').val(current_num);
            var goods_id = self.siblings('input').attr("goods_id"); //获取自定义属性商品id
            var myData = {"num": current_num, "goods_id": goods_id};
            addShopCart(myData);
        })
        $('.decrease').click(function () {
            var self = $(this);
            var current_num = parseInt(self.siblings('input').val());
            if (current_num > 1) {
                current_num -= 1;
                self.siblings('input').val(current_num);
                var goods_id = self.siblings('input').attr("goods_id"); //获取自定义属性商品id
                var myData = {"num": current_num, "goods_id": goods_id};
                addShopCart(myData);
            }
        })
        $('.am-icon-trash').click(function () {
            var self = $(this);
            var shopcart_id = self.attr("shopcart_id");
            var myData = {"shopcart_id": shopcart_id};
            $.post("${ctx}/shopCart/deleteShopCart.do", myData, function (data) {
                if (data.state == 0) {
                    console.info(data.msg);
                    self.parent().parent().remove();//删除当前元素
                } else {
                    alert(data.msg);
                }
            });

        })
    })
</script>
</body>
</html>
